package com.yloveg.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yloveg.common.FreemarkUtil;
import com.yloveg.dao.ProductContentMapper;
import com.yloveg.entity.ProductContent;
import com.yloveg.service.ProductContentService;

@Service
public class ProductContentServiceImpl implements ProductContentService {
 
    @Autowired
    private ProductContentMapper productContentMapper;

	@Override
	public int insertProduct(ProductContent product) {
		product.setCreateDate(new Date());
		product.setState(1);
		return productContentMapper.insertSelective(product);
	}

	@Override
	public int updateProduct(ProductContent product) {
		product.setUpdateDate(new Date());
		return productContentMapper.updateByPrimaryKeySelective(product);
	}

	@Override
	public PageInfo<ProductContent> queryProductContentPage(int page, int limit,ProductContent product) {
		PageHelper.startPage(page, limit);
		List<ProductContent> productList = productContentMapper.selectByTerm(product);
		for (ProductContent productContent : productList) {
			productContent.setPublisherState(FreemarkUtil.YesOrNoNmame(productContent.getPublisherState()));
			productContent.setProductType(FreemarkUtil.ProductTypeNmame(productContent.getProductType()));
		}
		PageInfo<ProductContent> resultPage=new PageInfo<ProductContent>(productList);
		return resultPage;
	}

	@Override
	public ProductContent selectByPrimaryKey(Long id) {
		return productContentMapper.selectByPrimaryKey(id);
	}

	
}
